import 'package:get_storage/get_storage.dart';

// 定义支持的目标APP类型
enum TargetApp { didi, meituan }

class RuleModel {
  String id; // 唯一ID
  TargetApp targetApp; // 目标APP
  bool isEnabled; // 是否启用

  // 滴滴规则字段
  double? minAmount; // 最小金额
  double? maxDistance; // 最大路程

  // 美团规则字段 (未来扩展)
  // String? keyword; 

  RuleModel({
    required this.id,
    required this.targetApp,
    this.isEnabled = true,
    this.minAmount,
    this.maxDistance,
  });

  // 从Map转换 (用于从GetStorage读取)
  factory RuleModel.fromMap(Map<String, dynamic> map) {
    return RuleModel(
      id: map['id'],
      targetApp: TargetApp.values.firstWhere((e) => e.toString() == map['targetApp']),
      isEnabled: map['isEnabled'],
      minAmount: map['minAmount'],
      maxDistance: map['maxDistance'],
    );
  }

  // 转换为Map (用于写入GetStorage)
  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'targetApp': targetApp.toString(),
      'isEnabled': isEnabled,
      'minAmount': minAmount,
      'maxDistance': maxDistance,
    };
  }
}